<?php

include(dirname(__FILE__).'/../../bootstrap/functional.php');

$browser = new bgMLTestFunctional(new sfBrowser());

$browser->
  get('/')->

  with('request')->begin()->
    isParameter('module', 'home')->
    isParameter('action', 'index')->
  end();

$browser->setHttpHeader('ACCEPT_LANGUAGE', 'en,it;q=0.7');
$browser->
  info('6 - User culture')->

  restart()->

  info('  6.1 - For the first request, symfony guesses the best culture')->
  get('/')->
  with('response')->isRedirected()->
  followRedirect()->
  with('user')->isCulture('en')->

  info('  6.2 - Available cultures are en, it, and es')->
  get('/fr/')->
  with('response')->isStatusCode(404)
;

$browser->setHttpHeader('ACCEPT_LANGUAGE', 'it;q=0.7');
$browser->
  info('  6.3 - The culture guessing is only for the first request')->

  get('/')->
  with('response')->isRedirected()->
  followRedirect()->
  with('user')->isCulture('en')
;

$browser->
info('  7.0 - Con i link si cambia la lingua')->
get('/it/')->
with('user')->isCulture('it')->
with('response')->begin()->
    isStatusCode(200)->
    info("7.1 Controllo che esca effettivamente la stringa italiana")->
    checkElement('body h1:contains("Benvenuto")', true)->
end()
;

$browser->
info('  8.0 - Controllo che ci sia il menu con gli elementi da non loggato')->
get('/it/')->
with('response')->begin()->
  isStatusCode(200)->
  checkElement('body h1:contains("Benvenuto")', true)->
  checkElement('body p:contains("Benvenuto")', true)->
  checkElement('ul[class="menu"] > li > a:contains("deck")', false)->
  checkElement('ul[class="menu"] > li > a:contains("logout")', false)->
  checkElement('ul[class="menu"] > li > a:contains("register")', true)->
  checkElement('ul[class="menu"] > li > a:contains("login")', true)->
end()->

info('  9.0 - effettuo il login')->
signin(array('username'=>'eux','password'=>'ostia'))->
get('/it/')->
with('response')->begin()->
info('  9.1 - il menu contiene le voci giuste')->
  checkElement('ul[class="menu"] > li > a:contains("deck")', true)->
  checkElement('ul[class="menu"] > li > a:contains("logout")', true)->
  checkElement('ul[class="menu"] > li > a:contains("register")', false)->
  checkElement('ul[class="menu"] > li > a:contains("login")', false)->
end()
;





